<!DOCTYPE html>
<html lang="en">
<head>
    {include file='public/header' /}
    <!-- Bootstrap Dropify CSS -->
    <link href="__PUBLIC__/admin/vendors/bower_components/dropify/dist/css/dropify.min.css" rel="stylesheet" type="text/css"/>

    <!-- Custom CSS -->
    {include file='public/comn_css' /}
</head>
<body>
<!--Preloader-->
<div class="preloader-it">
    <div class="la-anim-1"></div>
</div>
<!--/Preloader-->
<div class="wrapper  theme-5-active pimary-color-blue">

    <!-- Top Menu Items -->
    {include file='public/top_menu' /}
    <!-- /Top Menu Items -->

    <!-- Left Sidebar Menu -->
    {include file='public/sidebar' /}
    <!-- /Left Sidebar Menu -->

    <!-- Main Content -->
    <div class="page-wrapper">
        <div class="container-fluid">
            <!-- Title -->
            <div class="row heading-bg">
                <div class="col-lg-3 col-md-4 col-sm-4 col-xs-12">
                    <h5 class="txt-dark">权限分组</h5>
                </div>
                <!-- Breadcrumb -->
                <div class="col-lg-9 col-sm-8 col-md-8 col-xs-12">
                    <ol class="breadcrumb">
                        <li><a href="{:url('admin/index/index')}">系统首页</a></li>
                        <li><a href="{:url('admin/jurisdiction/index')}">权限分组</a></li>
                        <li class="active"><span>添加权限分组</span></li>
                    </ol>
                </div>
                <!-- /Breadcrumb -->
            </div>
            <!-- /Title -->

            <!-- Row -->
            <div class="row">
                <div class="col-lg-12 col-sm-12">
                    <div class="panel panel-default card-view">
                        <div class="panel-wrapper collapse in">
                            <div class="panel-body">
                                <form class="form-horizontal" id="system_form" method="post" action="{:url('doAdd')}" enctype="multipart/form-data">
                                    <div class="form-group">
                                        <label class="control-label mb-10 col-sm-2" for="title">分组名称:</label>
                                        <div class="col-sm-8">
                                            <input type="text" class="form-control" id="title" name="title" placeholder="请输入 分组名称" value="" required>
                                        </div>
                                    </div>

                                    <div class="form-group">
                                        <label class="control-label mb-10 col-sm-2">权限</label>
                                        <div class="col-sm-8">
                                        {notempty name='group'}
                                        {foreach name='group' item='value'}
                                            {php}$nav = \think\Db::name('admin_nav')->field('id, title')->where('group_id', $value['id'])->where('status', 1)->order('sort asc')->select();{/php}
                                            <div class="col-sm-12">
                                                <label class="control-label col-sm-2 text-left">{$value.title}</label>
                                            </div>
                                            {notempty name='nav'}
                                            {foreach name='nav' item='val' key='kk'}
                                            {php}$actions = \think\Db::name('action')->field('action, title, controller')->where('nav_id', $val['id'])->select();{/php}
                                            <div class="col-sm-8 col-md-offset-1">
                                                <div class="checkbox checkbox-success col-sm-2">
                                                    <input id="checkbox-{$key}{$kk}" type="checkbox" name="nav[]" value="{$val.id}" onchange="check_sub(this, '{$key}{$kk}');">
                                                    <label for="checkbox-{$key}{$kk}">
                                                        {$val.title}
                                                    </label>
                                                </div>
                                                <!--<label class="control-label col-sm-2 text-left" style="padding-left: 0;">{$val.title}</label>-->
                                            </div>
                                                {notempty name='actions'}
                                                <div class="col-sm-8 col-md-offset-2">
                                                    {foreach name='actions' item='v' key='k'}
                                                    <div class="checkbox checkbox-primary col-sm-2">
                                                        <input id="checkbox-{$key}-{$kk}-{$k}" class="checkbox-{$key}{$kk}" type="checkbox" name="juri[{$v.controller}][]" value="{$v.action}" onchange="check_parent(this, '{$key}{$kk}');">
                                                        <label for="checkbox-{$key}-{$kk}-{$k}">
                                                            {$v.title}
                                                        </label>
                                                    </div>
                                                    {/foreach}
                                                </div>
                                                {/notempty}
                                            {/foreach}
                                            {/notempty}
                                        {/foreach}
                                        {/notempty}
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <div class="col-sm-offset-2 col-sm-10">
                                            <button type="submit" class="btn btn-success"><span class="btn-text">提交</span></button>
                                        </div>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <!-- /Row -->

        </div>
        <!-- Footer -->
        {include file='public/footer' /}
        <!-- /Footer -->

    </div>
    <!-- /Main Content -->

</div>
<!-- /#wrapper -->

<!-- JavaScript -->
<!-- jQuery -->
<script src="__PUBLIC__/admin/vendors/bower_components/jquery/dist/jquery.min.js"></script>

<!-- Bootstrap Core JavaScript -->
<script src="__PUBLIC__/admin/vendors/bower_components/bootstrap/dist/js/bootstrap.min.js"></script>

<script src="__PUBLIC__/admin/vendors/bower_components/jasny-bootstrap/dist/js/jasny-bootstrap.min.js"></script>

<!-- Slimscroll JavaScript -->
<script src="__PUBLIC__/admin/dist/js/jquery.slimscroll.js"></script>

<!-- Fancy Dropdown JS -->
<script src="__PUBLIC__/admin/dist/js/dropdown-bootstrap-extended.js"></script>

<!-- Owl JavaScript -->
<script src="__PUBLIC__/admin/vendors/bower_components/owl.carousel/dist/owl.carousel.min.js"></script>

<!-- Switchery JavaScript -->
<script src="__PUBLIC__/admin/vendors/bower_components/switchery/dist/switchery.min.js"></script>

<!-- Init JavaScript -->
{include file='public/comn_js' /}

<script src="__PUBLIC__/admin/dist/js/jquery.form.js"></script>
<script src="__PUBLIC__/admin/vendors/layer/layer.js"></script>
<script>
    $('#system_form').submit(function() {
        var index;
        // submit the form
        $(this).ajaxSubmit({
            beforeSubmit: function () {
                index = layer.load(1, {shade:[0.6, '#000']});
            },
            success: function (responseText, statusText) {
                if (responseText)
                {
                    layer.msg('添加成功！', {shade: [0.6, '#000'], time:3000}, function () {
                        window.location.href="{:url('index')}";
                    });
                } else {
                    layer.msg('添加失败！', {shade: [0.6, '#000'], time:3000}, function () {
                        $('#system_form')[0].reset();
                    });
                }
            }
        });
        // return false to prevent normal browser submit and page navigation
        return false;
    });

    function check_sub(obj, kk) {
        if ($(obj).is(':checked'))
        {
            $('.checkbox-'+kk).prop('checked', true);
        } else {
            $('.checkbox-'+kk).prop('checked', false);
        }
    }

    function check_parent(obj, kk) {
        var total   = $('.checkbox-'+kk).length;
        console.log(total);
        var checked = 0;
        if ($(obj).is(':checked'))
        {
            $('#checkbox-'+kk).prop('checked', true);
        } else {
            $('.checkbox-'+kk).each(function () {
                if (!$(this).is(':checked'))
                {
                    checked ++;
                }
            });
            if (checked == total)
            {
                $('#checkbox-'+kk).prop('checked', false);
            }
        }
    }
</script>
</body>
</html>